import Vue from "vue";
import Router from "vue-router";
Vue.use(Router);

const originalPush = Router.prototype.push
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

let router = new Router({
    mode: "history",
    routes: [
        {
            path: '/',
            redirect: 'home',
        },
        {
            path: "/home",
            name: "home",
            component: ()=> import("client/views/home"),
            meta: { title: "首页" }
        },
        {
            path: "/404",
            name: "404",
            component: () => import("client/views/404"),
            meta: { title: "页面找不到" }
        },
        {
            path: "*",
            redirect: {
                name: "404"
            }
        }
    ]
});

router.beforeEach(async (to, from, next) => {
    scrollTo({top: 0});
    return next();
});

export default router;
